package online.afeibaili.storebackendframework

import com.fasterxml.jackson.databind.ObjectMapper
import online.afeibaili.storebackendframework.model.json.CouponJsonMapper
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import kotlin.random.Random
import kotlin.test.Test


/**
 * 其他测试
 *
 *@author AfeiBaili
 *@version 2025/10/20 18:33
 */

class OtherTest {
    @Test
    fun couponTest(){

    }

    @Test
    fun testJson() {
    }

    @Test
    fun test5() {
        val listOf: List<Int> = listOf(
            1, 2, 3
        )
        val listOf1: List<String> = listOf(
            "张三",
            "李四",
            "王五",
        )

        println(
            listOf.zip(listOf1)
                .windowed(2, 1) {
                    println(it)
                }
        )
    }

    @Test
    fun test4() {
        val couponJsonMappers: List<CouponJsonMapper> = listOf(
            CouponJsonMapper(1, Random.nextInt(0, 100).toLong(), 1),
            CouponJsonMapper(2, Random.nextInt(0, 100).toLong(), 2),
            CouponJsonMapper(3, Random.nextInt(0, 100).toLong(), 1),
            CouponJsonMapper(4, Random.nextInt(0, 100).toLong(), 4),
        )

        val pairs: List<Pair<Long, Int>> = listOf(
            Pair(1L, 1),
            Pair(4L, 2)
        )

        println(
            pairs.plus(couponJsonMappers)
                .map {
                    if (it is Pair<*, *>) {
                        CouponJsonMapper(it.first as Long, 0L, -(it.second as Int))
                    } else it
                }
                .filterIsInstance<CouponJsonMapper>()
                .groupBy { it.couponId }
                .map { it.value.reduce { c1, c2 -> c1 + c2 } }
                .filter { it.count > 0 }
                .toList()
        )
    }

    @Test
    fun test3() {
        println(ObjectMapper().writeValueAsString(Pair("xxx", 45)))
    }

    @Test
    fun test2() {
        println(List(5) {
            Random.nextInt()
        })
    }

    @Test
    fun test1() {
        val currentTimeMillis: Long = System.currentTimeMillis()
        println(LocalDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis), ZoneId.systemDefault()))
    }
}